package com.happy.study.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.happy.study.entity.NoteEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: Wuzh
 * @Description:
 * @Date Created in 21:47 2021/1/27
 * @return
 */

@Mapper
public interface NoteMapper extends BaseMapper<NoteEntity> {


    @Select ( value = "<script>select ni.id, ni.noteTitle, ni.level, fi.fileUrl AS fileUrl, ci.categoryName AS categoryName, ni.createTime from note_info ni " +
            "left join category_info ci on ci.id = ni.categoryId left join file_info fi on fi.relationId = ni.id and fi.type = 2 <where><if test='categoryId != null and categoryId != 0'>and ni.categoryId=#{categoryId}</if></where> order by ni.categoryId ASC limit #{start},#{end}</script>" )
    List<NoteEntity> queryList ( @Param ( "categoryId" ) int categoryId, @Param ( "start" ) int start, @Param ( "end" ) int end );

    @Select ( value = "<script>select count(*) from note_info ni left join category_info ci on ci.id = ni.categoryId left join file_info fi on fi.relationId = ni.id and fi.type = 2 <where><if test='categoryId != null and categoryId != 0'>and ni.categoryId=#{categoryId}</if></where></script>")
    int queryCount ( @Param ( "categoryId" ) int categoryId );

}
